package com.zy.cat.entity.dev.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.zy.cat.entity.dev.CatDevRelation;
public interface CatDevRelationRepository extends JpaSpecificationExecutor<CatDevRelation>,  JpaRepository<CatDevRelation, String>{

	CatDevRelation findByPid(String pid);
	CatDevRelation findByunionid(String unionid);
	/**
	 * 
	 * @info 获取未激活的邀请人信息
	 * @author Link
	 * @date 2019-11-26 16:56
	 * @param unionid
	 * @param time
	 * @return
	 */
	@Query("from CatDevRelation where unionid=:unionid and stime<=:time and etime>=:time and ystatus=0")
	CatDevRelation findInviteUser(@Param("unionid")String unionid,@Param("time")String time);
	
	/**
	 * 获取邀请成功人数
	 * @param ypid 推广者pid
	 * @param ytype 邀请类型（0.直接邀请、1.互拆红包邀请）
	 * @param ystatus 邀请状态（0.已点击邀请链接、1.已注册激活）
	 * @return
	 */
	int countByYpidAndYtypeAndYstatus(@Param("ypid")String ypid,@Param("ytype")int ytype,@Param("ystatus")int ystatus);
}
